﻿using CleverDD.Model.Communication.PLC;
using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CleverDD.Helper.Interface
{
    /// <summary>
    /// ReadAll方法传的是PlcAddressInfo集合 WritePlc 方法传的是PlcAddressInfo对象
    /// 其余方法传的对应的地址（string）,不同的类型的值
    /// 字符串的读写，定义了俩参数，长度、编码类型，单调用读写字符串方法时，这俩参数可不传。
    /// 三菱单独调用方法时，长度也必须传
    /// 实现字符串读写的方法时，要处理长度。字符编码不传（即是默认值的情况）
    /// </summary>
    public interface IPlcReadAndWriteInterface
    {
        OperateResult ConnPlc(string ip, int port);

        OperateResult ClosePlc();


        #region 读取PLC

        OperateResult ReadAll(List<PlcAddressInfoEntity> plcAddressInfoList);
        OperateResult<bool> ReadBool(string address);

        OperateResult<byte> ReadByte(string address);

        OperateResult<short> ReadShort(string address);

        OperateResult<ushort> ReaduShort(string address);

        OperateResult<int> ReadInt(string address);

        OperateResult<uint> ReaduInt(string address);

        OperateResult<long> ReadLong(string address);

        OperateResult<ulong> ReaduLong(string address);


        OperateResult<float> ReadFloat(string address);

        OperateResult<double> ReadDouble(string address);

        /// <summary>
        /// 读取字符串的方法，支持不传长度跟编码格式读写
        /// 重写的这个方法，里面要有 EncodingType不同时的处理，length为0时的处理
        /// 默认的ReadAll()方法里,传的是PlcAddressInfo对象，对象的默认值是0，相当于是调用的这个方法的全参数模式，而不是没传参数
        /// </summary>
        /// <param name="address"></param>
        /// <param name="length"></param>
        /// <param name="encodingType"></param>
        /// <returns></returns>
        OperateResult<string> ReadString(string address, ushort length = 0, EncodingType encodingType = EncodingType.None);

        #endregion

        #region 写入PLC

        OperateResult WritePlc(PlcAddressInfoEntity plcAddressInfo, string value);
        OperateResult WriteBool(string address, bool value);

        OperateResult WriteByte(string address, byte value);

        OperateResult WriteShort(string address, short value);

        OperateResult WriteuShort(string address, ushort value);

        OperateResult WriteInt(string address, int value);

        OperateResult WriteuInt(string address, uint value);

        OperateResult WriteLong(string address, long value);

        OperateResult WriteuLong(string address, ulong value);

        OperateResult WriteFloat(string address, float value);

        OperateResult WriteDouble(string address, double value);

        /// <summary>
        /// 写入字符串的方法，支持不传长度跟编码格式读写
        /// 重写的这个方法，里面要有 EncodingType不同时的处理，length为0时的处理，三菱的HSL没有不传长度的写法，所以三菱的没有Length为0时的处理
        /// 默认的WritePlc()方法里,传的是PlcAddressInfo对象，对象的默认值是0，相当于是调用的这个方法的全参数模式，而不是没传参数
        /// </summary>
        /// <param name="address"></param>
        ///  <param name="value"></param>
        /// <param name="length"></param>
        /// <param name="encodingType"></param>
        /// <returns></returns>
        OperateResult WriteString(string address, string value, int length = 0, EncodingType encodingType = EncodingType.None);

        #endregion
    }
}
